package ca.sfu.util;

import edu.cmu.tetrad.data.Knowledge;
import edu.cmu.tetrad.graph.Graph;
import edu.cmu.tetrad.search.IndTestType;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.List;
import edu.cmu.tetradapp.model.*;

public class GesMultipleParams implements SearchParams{
	private GesParams gesParams;
	private int graphNumber; // The number of graphs to search for
	
	public GesMultipleParams(){
		this.gesParams = new GesParams();
	}
	
    //============================PUBLIC METHODS==========================//

	public int getGraphNumber(){
		return graphNumber;
	}
	public void setGraphNumber(int i){
		graphNumber=i;
	}
	
    public IndTestParams getIndTestParams() {
        return gesParams.getIndTestParams();
    }

    public void setIndTestParams2(IndTestParams indTestParams) {
        if (!(indTestParams instanceof GesIndTestParams)) {
            throw new IllegalArgumentException(
                    "Illegal IndTestParams " + "in GesIndTestParams");
        }
        gesParams.setIndTestParams2((GesIndTestParams) indTestParams);
    }

    public List<String> getVarNames() {
        return gesParams.getVarNames();
    }

    public void setVarNames(List<String> varNames) {
        gesParams.setVarNames(varNames);
    }

    public Graph getSourceGraph() {
        return gesParams.getSourceGraph();
    }

    public void setSourceGraph(Graph graph) {
        gesParams.setSourceGraph(graph);
    }

    public void setIndTestType(IndTestType testType) {
        gesParams.setIndTestType(testType);
    }

    public IndTestType getIndTestType() {
        return gesParams.getIndTestType();
    }

    //  Wrapping GesIndTestParams...

    public double getCellPrior() {
        return ((GesIndTestParams) gesParams.getIndTestParams()).getCellPrior();
    }

    public void setCellPrior(double cellPrior) {
        ((GesIndTestParams) gesParams.getIndTestParams()).setCellPrior(cellPrior);
    }

    public double getStructurePrior() {
        return ((GesIndTestParams) gesParams.getIndTestParams()).getStructurePrior();
    }

    public void setStructurePrior(double structurePrior) {
    	((GesIndTestParams) gesParams.getIndTestParams()).setStructurePrior(structurePrior);
    }

    public Knowledge getKnowledge() {
        return new Knowledge(gesParams.getKnowledge());
    }

    public void setKnowledge(Knowledge knowledge) {
        if (knowledge == null) {
            throw new NullPointerException("Cannot set a null knowledge.");
        }

        gesParams.setKnowledge(new Knowledge(knowledge));
    }

    /**
     * Adds semantic checks to the default deserialization method. This method
     * must have the standard signature for a readObject method, and the body of
     * the method must begin with "s.defaultReadObject();". Other than that, any
     * semantic checks can be specified and do not need to stay the same from
     * version to version. A readObject method of this form may be added to any
     * class, even if Tetrad sessions were previously saved out using a version
     * of the class that didn't include it. (That's what the
     * "s.defaultReadObject();" is for. See J. Bloch, Effective Java, for help.
     *
     * @throws java.io.IOException
     * @throws ClassNotFoundException
     */
    private void readObject(ObjectInputStream s)
            throws IOException, ClassNotFoundException {
        s.defaultReadObject();

        if (gesParams.getKnowledge()== null) {
            throw new NullPointerException();
        }

        if (gesParams.getIndTestParams()== null) {
            throw new NullPointerException();
        }
    }
}
